<template>
	<view class="content">
		<view class="tips-item">
			<view class="tip iconfont icon-gantanhao">
				<text class="txt">提示：所填写的内容和所提供的材料真实准确，如有虚报冒领等行为，将承担相应的法律责任并接受相关处罚。</text>
			</view>
		</view>
		<view class="info-block">
			<view class="title FangZhengHanZhenGuangBiaoJianTi">附件信息</view>
			<view class="form-item">
				<view style="display: flex;flex-direction: row;align-items: center;">
					<view style="color: #C10A11;">*</view>
					<view class="form-label">申请人身份证</view>
				</view>
				<view class="upload-block1">
					<view class="img-item">
						<image style="height: 200rpx;" mode="aspectFill" @click="chooseImage(1)"
							:src="form.idCardJust?form.idCardJust:imageUrl+'/company_auth/front.png'" class="photo">
						</image>
						<image style="height: 200rpx;" mode="aspectFill" @click="chooseImage(2)"
							:src="form.idCardBack?form.idCardBack:imageUrl+'/company_auth/opposite.png'" class="photo">
						</image>
					</view>
				</view>
			</view>
			<view class="form-item">
				<view style="display: flex;flex-direction: row;align-items: center;">
					<view style="color: #C10A11;">*</view>
					<view class="form-label">营业执照</view>
				</view>
				<view class="upload-block">
					<image :src="form.upLicense" class="photo" style="width: 340rpx;height: 200rpx;" mode="aspectFill"
						v-if="form.upLicense">
					</image>
					<view class="photo" v-else @click="chooseImage(3)">
						<image :src="imageUrl+'/company_auth/jia.png'" style="width: 100rpx;height: 100rpx;"></image>
					</view>
				</view>
			</view>
			<view class="agreement-block">
				<checkbox-group @change="checkChange">
					<checkbox color="#FF7626" id="check" class="checkbox" /><label for="check"
						class="radio-label">我已阅读并同意<text class="agreement">
							《贷款申请通知》</text><text class="agreement">《个人征信业务授权书》</text></label>
				</checkbox-group>
			</view>
		</view>
		<view style="display: flex;flex-direction: row;">
			<view class="btn1" @click="goBack">上一步</view>
			<view class="btn" @click="handleSave">确认并提交</view>
		</view>
	</view>
</template>

<script>
	import {
		validate
	} from '@/util/validate.js'
	import {
		uploadFile
	} from '@/api/file.js'
	export default {
		data() {
			return {
				form: {
					idCardJust: '',
					idCardBack: '',
					upLicense: '',
					checked: [],
				},
				imageUrl: '',
				rules: {
					idCardJust: {
						name: '身份证正面',
						required: true
					},
					identity: {
						name: '身份证国徽面',
						required: true
					},
					upLicense: {
						name: '营业执照',
						required: true
					},
					checked: {
						name: '',
						required: false,
						validator: function(value, form, callback) {
							if (value.length == 0) {
								callback('请勾选同意协议！');
							}
							callback();
						}
					},
				}
			}
		},
		methods: {
			chooseImage(category) {
				uni.chooseImage({
					count: 1,
					sizeType: ['compressed'],
					sourceType: ['album'],
					success: (e) => {
						uni.showLoading({
							title: '上传中',
							mask: true
						})
						uploadFile(e.tempFilePaths[0]).then((res) => {
							const data = JSON.parse(res.data);
							uni.hideLoading()
							if (data.code == 200) {
								this.showToast('上传成功')
								if (category == 1) {
									this.form.idCardJust = data.data
								} else if (category == 2) {
									this.form.idCardBack = data.data
								} else if (category == 3) {
									this.form.upLicense = data.data
								}
							} else {
								this.showToast(data.msg)
							}
						}).catch((res) => {
							uni.hideLoading()
							this.showToast('上传失败');
						})
					}
				})
			},
			checkChange(e) {
				this.form.checked = e.detail.value;
			},
			goBack() {
				uni.redirectTo({
					url: '/page_other/business_loan/security_information'
				})
			},
			handleSave() {
				if (validate(this.form, this.rules)) {
					uni.showToast({
						title: '提交成功',
						icon: 'success',
						duration: 1000,
						mask: true,
						success: function() {
							setTimeout(function() {
								uni.switchTab({
									url: '/pages/home/index'
								})
							}, 1000)
						},
					})
				}
			}
		},
		onLoad(e) {
			this.imageUrl = this.globalConfig.imageUrl;
		}
	}
</script>

<style lang="scss">
	.content {
		width: 100%;
		padding: 30rpx;

		.tips-item {
			display: flex;
			flex-direction: column;
			color: #F4982B;
			background: #FFF0D6;
			padding: 20rpx;
			border-radius: 20rpx;

			.tips {
				width: 100%;
				display: flex;
				align-items: center;
				padding: 20rpx;
				font-size: 24rpx;
			}

			.iconfont {
				font-size: 14px;

				.txt {
					margin-left: 16rpx;
					font-size: 14px;
					line-height: 50rpx;
				}
			}
		}

		.info-block {
			margin-top: 30rpx;
			background: #fff;
			border-radius: 20rpx;
			padding: 20rpx;

			.title {
				margin-top: 30rpx;
				font-size: 38rpx;
			}

			.form-item {
				display: flex;
				flex-direction: column;
				border-bottom: 1px solid #efefef;
				padding-top: 30rpx;

				.form-label {
					font-size: 34rpx;
					color: #999;
				}

				.upload-block {
					width: 100%;
					padding-bottom: 30rpx;
					display: flex;
					flex-direction: column;
					//align-items: center;
					justify-content: center;
					border-bottom: 1px solid #efefef;

					.title {
						margin-top: 30rpx;
						margin-bottom: 20rpx;
					}

					.photo {
						width: 340rpx;
						height: 220rpx;
						background: #efefef;
						border-radius: 20rpx;
						display: flex;
						justify-content: center;
						align-items: center;
						margin-top: 30rpx;

					}

					.look {
						color: #D8030E;
						font-size: 15px;
						margin-bottom: 30rpx;
						//margin-top: 10rpx;
					}

					.upload-tips {
						font-size: 28rpx;
						color: #335DC5;
						margin-top: 20rpx;
					}
				}


				.upload-block1 {
					width: 100%;
					padding-bottom: 30rpx;
					display: flex;
					flex-direction: column;
					justify-content: space-between;

					.title {
						margin-top: 40rpx;
						margin-bottom: 30rpx;
					}

					.img-item {
						display: flex;
						flex-direction: row;
						justify-content: space-between;

						.photo {
							width: 460rpx;
							height: 420rpx;
							background: #efefef;
							border-radius: 20rpx;
							margin-right: 10rpx;
							margin-top: 30rpx;
						}

						.photo:last-child {
							margin-right: 0;
						}

						.look {
							color: #D8030E;
							padding: 20rpx 0;
							font-size: 14px;
						}

						.upload-tips {
							font-size: 28rpx;
							color: #335DC5;
							margin-top: 20rpx;
						}
					}
				}
			}

			.agreement-block {
				width: 100%;
				margin-top: 40rpx;
				display: flex;
				flex-direction: row;

				.radio-label {
					font-size: 28rpx;

					.agreement {
						color: #FF0015;
					}
				}

				.checkbox {
					transform: scale(0.7);
				}
			}
		}

		.btn1 {
			width: 290rpx;
			height: 90rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			border: 1px solid #FF0015;
			color: #FF0015;
			font-size: 28rpx;
			border-radius: 50rpx;
			margin: 0 auto;
			margin-top: 30rpx;
		}

		.btn {
			width: 290rpx;
			height: 90rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			background: #FF0015;
			color: #fff;
			font-size: 28rpx;
			border-radius: 50rpx;
			margin: 0 auto;
			margin-top: 30rpx;
		}
	}
</style>